//
//  SAMemberIntegralVC.m
//  saasRetail
//
//  Created by 黄志刚 on 2021/6/21.
//

#import "SAMemberIntegralVC.h"
#import "SASystemSettingsListAPI.h"
#import "SACommoditySpecialFeesModel.h"
#import "SASystemSettingsCheckAPI.h"
#import "HDDatePickerView.h"

@interface SAMemberIntegralVC ()<HTTPAPIDelegate,UITextFieldDelegate>

@property (nonatomic, strong) UIButton *switchBtn;
@property (nonatomic, strong) UIButton *editBtn;
@property (nonatomic, strong) UIButton *saveBtn;
@property (nonatomic, strong) UIButton *cancleBtn;
@property (nonatomic, strong) UITextField *consumptionTf;
@property (nonatomic, strong) UITextField *consumptionIntegralTf;
@property (nonatomic, strong) UITextField *topUpTf;
@property (nonatomic, strong) UITextField *topUpIntegralTf;
@property (nonatomic, strong) UIView *line2;
@property (nonatomic, strong) UIView *line3;
@property (nonatomic, strong) UIView *line4;
@property (nonatomic, strong) UIView *line5;

@property (nonatomic, strong) UIButton *switchBtn2;
@property (nonatomic, strong) UIButton *editBtn2;
@property (nonatomic, strong) UIButton *saveBtn2;
@property (nonatomic, strong) UIButton *cancleBtn2;
@property (nonatomic, strong) UITextField *useIntegralTf;
@property (nonatomic, strong) UITextField *deductionIntegralTf;
@property (nonatomic, strong) UIView *line6;
@property (nonatomic, strong) UIView *line7;

@property (nonatomic, strong) SASystemSettingsListAPI *systemSettingsListAPI;
@property (nonatomic, strong) NSMutableArray<SACommoditySpecialFeesModel *> *dataMarr;

@property (nonatomic, strong) SASystemSettingsCheckAPI *systemSettingsCheckAPI;
@property (nonatomic, strong) SASystemSettingsCheckAPI *systemSettingsCheckAPI2;
@property (nonatomic, strong) SASystemSettingsCheckAPI *systemSettingsCheckAPI3;
@property (nonatomic, strong) SASystemSettingsCheckAPI *systemSettingsCheckAPI4;
@property (nonatomic, strong) SASystemSettingsCheckAPI *systemSettingsCheckAPI5;
@property (nonatomic, strong) SASystemSettingsCheckAPI *systemSettingsCheckAPI6;

@property (nonatomic, strong) NSString *templateId;
@property (nonatomic, strong) NSString *switchSettingsId;
@property (nonatomic, strong) NSString *consumptionSettingsId;
@property (nonatomic, strong) NSString *topUpSettingsId;
@property (nonatomic, strong) NSString *useSettingsId;
@property (nonatomic, strong) NSString *deductionSettingsId;

@property (nonatomic, strong) UIButton *switchBtn3;
@property (nonatomic, strong) UIButton *editBtn3;
@property (nonatomic, strong) UIButton *saveBtn3;
@property (nonatomic, strong) UIButton *cancleBtn3;
@property (nonatomic, strong) UIButton *dateBtn;
@property (nonatomic, strong) NSString *dateId;

@end

@implementation SAMemberIntegralVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

#pragma mark - HTTPAPIDelegate
- (void)fetchData:(id)data fromServerSuccessedWithAPI:(HTTPAPI *)api {
    if (self.systemSettingsListAPI == api) {
        self.dataMarr = [SACommoditySpecialFeesModel mj_objectArrayWithKeyValuesArray:data[@"data"][@"member_points_setting"][@"childSettings"]];
        self.templateId = data[@"data"][@"member_points_setting"][@"templateId"];
        for (SACommoditySpecialFeesModel *model in self.dataMarr) {
            if ([model.code isEqualToString:@"points_switch"]) {
                self.switchSettingsId = model.settingsId;
                NSArray *arr = [model.value componentsSeparatedByString:@","];
                if (arr.count > 1) {
                    NSString *i = arr[0];
                    NSString *j = arr[1];
                    self.switchBtn.selected = [i isEqualToString:@"1"];
                    self.switchBtn2.selected = [j isEqualToString:@"1"];
                    if (arr.count > 2) {
                        NSString *k = arr[2];
                        self.switchBtn3.selected = [k isEqualToString:@"1"];
                    }
                }
            }else if ([model.code isEqualToString:@"consumption_gift"]) {
                self.consumptionSettingsId = model.settingsId;
                NSArray *arr = [model.value componentsSeparatedByString:@","];
                if (arr.count > 1) {
                    self.consumptionTf.text = arr[0];
                    self.consumptionIntegralTf.text = arr[1];
                }
            }else if ([model.code isEqualToString:@"top_up_gift"]) {
                self.topUpSettingsId = model.settingsId;
                NSArray *arr = [model.value componentsSeparatedByString:@","];
                if (arr.count > 1) {
                    self.topUpTf.text = arr[0];
                    self.topUpIntegralTf.text = arr[1];
                }
            }else if ([model.code isEqualToString:@"deduction"]) {
                self.useSettingsId = model.settingsId;
                NSArray *arr = [model.value componentsSeparatedByString:@","];
                if (arr.count > 0) {
                    self.useIntegralTf.text = arr[0];
                }
            }else if ([model.code isEqualToString:@"deduction_limit"]) {
                self.deductionSettingsId = model.settingsId;
                NSArray *arr = [model.value componentsSeparatedByString:@","];
                if (arr.count > 0) {
                    self.deductionIntegralTf.text = arr[0];
                }
            }else if ([model.code isEqualToString:@"clearing_date"]) {
                self.dateId = model.settingsId;
                [self.dateBtn setTitle:model.value forState:UIControlStateNormal];
            }
        }
    }else {
        [self.systemSettingsListAPI sendRequestToServerWithActivityViewAndMask:GET];
    }
}

- (void)fetchDataFromServerFailedWithError:(NSError *)error API:(HTTPAPI *)api {
    
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    if (string.length == 0) {
        return YES;
    }
    if (textField.text.length > 7) {
        return NO;
    }
    if ([textField.text isEqualToString:@"0"]) {
        textField.text = @"";
    }
    return [self validateNumber:string];
}

- (BOOL)validateNumber:(NSString*)number {
    BOOL res = YES;
    NSCharacterSet* tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
    int i = 0;
    while (i < number.length) {
        NSString * string = [number substringWithRange:NSMakeRange(i, 1)];
        NSRange range = [string rangeOfCharacterFromSet:tmpSet];
        if (range.length == 0) {
            res = NO;
            break;
        }
        i++;
    }
    return res;
}

#pragma mark - event
-(void)clickedSwitchBtn:(UIButton *)sender {
    sender.selected = !sender.isSelected;
    NSString *i = @"0";
    NSString *j = @"0";
    NSString *k = @"0";
    if (self.switchBtn.selected == YES) {
        i = @"1";
    }
    if (self.switchBtn2.selected == YES) {
        j = @"1";
    }
    if (self.switchBtn3.selected == YES) {
        k = @"1";
    }
    self.systemSettingsCheckAPI.value = [NSString stringWithFormat:@"%@,%@,%@",i,j,k];
    self.systemSettingsCheckAPI.settingsId = self.switchSettingsId;
    self.systemSettingsCheckAPI.parentId = self.templateId;
    [self.systemSettingsCheckAPI sendRequestToServerWithActivityViewAndMask:POST];
}

-(void)clickedEditBtn {
    self.editBtn.hidden = YES;
    self.saveBtn.hidden = NO;
    self.cancleBtn.hidden = NO;
    self.line2.hidden = NO;
    self.line3.hidden = NO;
    self.line4.hidden = NO;
    self.line5.hidden = NO;
    self.consumptionTf.textColor = kBlackColor;
    self.consumptionIntegralTf.textColor = kBlackColor;
    self.topUpTf.textColor = kBlackColor;
    self.topUpIntegralTf.textColor = kBlackColor;
    
    self.consumptionTf.userInteractionEnabled = YES;
    self.consumptionIntegralTf.userInteractionEnabled = YES;
    self.topUpTf.userInteractionEnabled = YES;
    self.topUpIntegralTf.userInteractionEnabled = YES;
}

-(void)clickedSaveBtn {
    if (self.consumptionTf.text.length == 0 || self.consumptionIntegralTf.text.length == 0 || self.topUpTf.text.length == 0 || self.topUpIntegralTf .text.length == 0) {
        [Prompt popPromptViewWithMsg:@"请设置赠送规则" duration:2];
        return;
    }
    
    self.editBtn.hidden = NO;
    self.saveBtn.hidden = YES;
    self.cancleBtn.hidden = YES;
    self.line2.hidden = YES;
    self.line3.hidden = YES;
    self.line4.hidden = YES;
    self.line5.hidden = YES;
    self.consumptionTf.textColor = kPinkColor;
    self.consumptionIntegralTf.textColor = kPinkColor;
    self.topUpTf.textColor = kPinkColor;
    self.topUpIntegralTf.textColor = kPinkColor;
    
    self.consumptionTf.userInteractionEnabled = NO;
    self.consumptionIntegralTf.userInteractionEnabled = NO;
    self.topUpTf.userInteractionEnabled = NO;
    self.topUpIntegralTf.userInteractionEnabled = NO;
    
    self.systemSettingsCheckAPI2.value = [NSString stringWithFormat:@"%@,%@",self.consumptionTf.text,self.consumptionIntegralTf.text];
    self.systemSettingsCheckAPI2.settingsId = self.consumptionSettingsId;
    self.systemSettingsCheckAPI2.parentId = self.templateId;
    [self.systemSettingsCheckAPI2 sendRequestToServerWithActivityViewAndMask:POST];
    
    self.systemSettingsCheckAPI3.value = [NSString stringWithFormat:@"%@,%@",self.topUpTf.text,self.topUpIntegralTf.text];
    self.systemSettingsCheckAPI3.settingsId = self.topUpSettingsId;
    self.systemSettingsCheckAPI3.parentId = self.templateId;
    [self.systemSettingsCheckAPI3 sendRequestToServerWithActivityViewAndMask:POST];
    
}

-(void)clickedCancleBtn {
    self.editBtn.hidden = NO;
    self.saveBtn.hidden = YES;
    self.cancleBtn.hidden = YES;
    self.line2.hidden = YES;
    self.line3.hidden = YES;
    self.line4.hidden = YES;
    self.line5.hidden = YES;
    self.consumptionTf.textColor = kPinkColor;
    self.consumptionIntegralTf.textColor = kPinkColor;
    self.topUpTf.textColor = kPinkColor;
    self.topUpIntegralTf.textColor = kPinkColor;
    
    self.consumptionTf.userInteractionEnabled = NO;
    self.consumptionIntegralTf.userInteractionEnabled = NO;
    self.topUpTf.userInteractionEnabled = NO;
    self.topUpIntegralTf.userInteractionEnabled = NO;
    
    [self.systemSettingsListAPI sendRequestToServerWithActivityViewAndMask:GET];
}

-(void)clickedEditBtn2 {
    self.editBtn2.hidden = YES;
    self.saveBtn2.hidden = NO;
    self.cancleBtn2.hidden = NO;
    self.line6.hidden = NO;
    self.line7.hidden = NO;
    self.useIntegralTf.textColor = kBlackColor;
    self.deductionIntegralTf.textColor = kBlackColor;
    
    self.useIntegralTf.userInteractionEnabled = YES;
    self.deductionIntegralTf.userInteractionEnabled = YES;
}

-(void)clickedSaveBtn2 {
    if (self.useIntegralTf.text.length == 0 || self.deductionIntegralTf.text.length == 0) {
        [Prompt popPromptViewWithMsg:@"请设置抵扣规则" duration:2];
        return;
    }
    
    self.editBtn2.hidden = NO;
    self.saveBtn2.hidden = YES;
    self.cancleBtn2.hidden = YES;
    self.line6.hidden = YES;
    self.line7.hidden = YES;
    self.useIntegralTf.textColor = kPinkColor;
    self.deductionIntegralTf.textColor = kPinkColor;
    
    self.useIntegralTf.userInteractionEnabled = NO;
    self.deductionIntegralTf.userInteractionEnabled = NO;
    
    self.systemSettingsCheckAPI4.value = self.useIntegralTf.text;
    self.systemSettingsCheckAPI4.settingsId = self.useSettingsId;
    self.systemSettingsCheckAPI4.parentId = self.templateId;
    [self.systemSettingsCheckAPI4 sendRequestToServerWithActivityViewAndMask:POST];
    
    self.systemSettingsCheckAPI5.value =  self.deductionIntegralTf.text;
    self.systemSettingsCheckAPI5.settingsId = self.deductionSettingsId;
    self.systemSettingsCheckAPI5.parentId = self.templateId;
    [self.systemSettingsCheckAPI5 sendRequestToServerWithActivityViewAndMask:POST];
}

-(void)clickedCancleBtn2 {
    self.editBtn2.hidden = NO;
    self.saveBtn2.hidden = YES;
    self.cancleBtn2.hidden = YES;
    self.line6.hidden = YES;
    self.line7.hidden = YES;
    self.useIntegralTf.textColor = kPinkColor;
    self.deductionIntegralTf.textColor = kPinkColor;
    
    self.useIntegralTf.userInteractionEnabled = NO;
    self.deductionIntegralTf.userInteractionEnabled = NO;
    
    [self.systemSettingsListAPI sendRequestToServerWithActivityViewAndMask:GET];
}

-(void)clickedEditBtn3 {
    self.editBtn3.hidden = YES;
    self.saveBtn3.hidden = NO;
    self.cancleBtn3.hidden = NO;
    self.dateBtn.backgroundColor = kColor(254, 248, 240, 1);
    self.dateBtn.userInteractionEnabled = YES;
}

-(void)clickedSaveBtn3 {
    self.editBtn3.hidden = NO;
    self.saveBtn3.hidden = YES;
    self.cancleBtn3.hidden = YES;
    self.dateBtn.backgroundColor = [UIColor whiteColor];
    self.dateBtn.userInteractionEnabled = NO;
    
    self.systemSettingsCheckAPI6.value = self.dateBtn.titleLabel.text;
    self.systemSettingsCheckAPI6.settingsId = self.dateId;
    self.systemSettingsCheckAPI6.parentId = self.templateId;
    [self.systemSettingsCheckAPI6 sendRequestToServerWithActivityViewAndMask:POST];
    
}

-(void)clickedCancleBtn3 {
    self.editBtn3.hidden = NO;
    self.saveBtn3.hidden = YES;
    self.cancleBtn3.hidden = YES;
    self.dateBtn.backgroundColor = [UIColor whiteColor];
    self.dateBtn.userInteractionEnabled = NO;
}

-(void)clickedDateBtn {
    WeakSelf
    HDDatePickerView *pickerView = [[HDDatePickerView alloc] initWithSlectedDate:self.dateBtn.titleLabel.text];
    [pickerView show];
    pickerView.selectDateBlock = ^(NSString *selectedDate) {
        [weakSelf.dateBtn setTitle:selectedDate forState:UIControlStateNormal];
    };
}


#pragma mark - initUI
-(void)initUI {
    [self setNavigationItemBackBBIAndTitle:@"会员积分"];
    [self setBgImage:nil];
    self.view.backgroundColor = kBgColor;
    
    UIView *whiteView = [[UIView alloc] initWithFrame:SARectMake(0, StatusHeight, kBaseScreenWidth, 135)];
    whiteView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:whiteView];
    
    UILabel *presentLab = [[UILabel alloc] initWithFrame:SARectMake(20, 0, 70, 35)];
    presentLab.text = @"赠送积分";
    presentLab.textColor = kGrayColor;
    presentLab.textAlignment = NSTextAlignmentLeft;
    presentLab.font = kFont(15);
    [whiteView addSubview:presentLab];
    
    UIButton *switchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    switchBtn.frame = SARectMake(90, 0, 60, 35);
    [switchBtn setImage:[UIImage imageNamed:@"gray_switch"] forState:UIControlStateNormal];
    [switchBtn setImage:[UIImage imageNamed:@"green_switch"] forState:UIControlStateSelected];
    [switchBtn addTarget:self action:@selector(clickedSwitchBtn:) forControlEvents:UIControlEventTouchUpInside];
    [whiteView addSubview:switchBtn];
    self.switchBtn = switchBtn;
    
    UIButton *editBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    editBtn.frame = SARectMake(kBaseScreenWidth - 65, 0, 50, 35);
    [editBtn setImage:[UIImage imageNamed:@"bule_edit"] forState:UIControlStateNormal];
    [editBtn addTarget:self action:@selector(clickedEditBtn) forControlEvents:UIControlEventTouchUpInside];
    [whiteView addSubview:editBtn];
    self.editBtn = editBtn;
    
    UIButton *saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    saveBtn.frame = SARectMake(kBaseScreenWidth - 65, 0, 50, 35);
    [saveBtn setTitle:@"保存" forState:UIControlStateNormal];
    [saveBtn setTitleColor:kColor(70, 112, 251, 1) forState:UIControlStateNormal];
    [saveBtn addTarget:self action:@selector(clickedSaveBtn) forControlEvents:UIControlEventTouchUpInside];
    saveBtn.hidden = YES;
    saveBtn.titleLabel.font = kFont(15);
    [whiteView addSubview:saveBtn];
    self.saveBtn = saveBtn;
    
    UIButton *cancleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    cancleBtn.frame = SARectMake(kBaseScreenWidth - 120, 0, 50, 35);
    [cancleBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancleBtn setTitleColor:kColor(70, 112, 251, 1) forState:UIControlStateNormal];
    [cancleBtn addTarget:self action:@selector(clickedCancleBtn) forControlEvents:UIControlEventTouchUpInside];
    cancleBtn.hidden = YES;
    cancleBtn.titleLabel.font = kFont(15);
    [whiteView addSubview:cancleBtn];
    self.cancleBtn = cancleBtn;
    
    UIView *line = [[UIView alloc] initWithFrame:SARectMake(0, 34, kBaseScreenWidth, 1)];
    line.backgroundColor = kLineColor;
    [whiteView addSubview:line];
    
    UILabel *consumptionLab = [[UILabel alloc] initWithFrame:SARectMake(20, 35, 40, 50)];
    consumptionLab.text = @"消费";
    consumptionLab.textAlignment = NSTextAlignmentLeft;
    consumptionLab.font = kFont(15);
    consumptionLab.textColor = kBlackColor;
    [whiteView addSubview:consumptionLab];
    
    UILabel *consumptionLab2 = [[UILabel alloc] initWithFrame:SARectMake(140, 35, 50, 50)];
    consumptionLab2.text = @"元赠送";
    consumptionLab2.textAlignment = NSTextAlignmentLeft;
    consumptionLab2.font = kFont(15);
    consumptionLab2.textColor = kBlackColor;
    [whiteView addSubview:consumptionLab2];
    
    UILabel *consumptionLab3 = [[UILabel alloc] initWithFrame:SARectMake(270, 35, 50, 50)];
    consumptionLab3.text = @"个积分";
    consumptionLab3.textAlignment = NSTextAlignmentLeft;
    consumptionLab3.font = kFont(15);
    consumptionLab3.textColor = kBlackColor;
    [whiteView addSubview:consumptionLab3];
    
    UIView *line2 = [[UIView alloc] initWithFrame:SARectMake(55, 74, 80, 1)];
    line2.backgroundColor = kBlackColor;
    [whiteView addSubview:line2];
    line2.hidden = YES;
    self.line2 = line2;
    
    UIView *line3 = [[UIView alloc] initWithFrame:SARectMake(190, 74, 80, 1)];
    line3.backgroundColor = kBlackColor;
    [whiteView addSubview:line3];
    line3.hidden = YES;
    self.line3 = line3;
    
    UITextField *consumptionTf = [[UITextField alloc] initWithFrame:SARectMake(55, 35, 80, 50)];
    consumptionTf.placeholder = @"";
    consumptionTf.font = kFont(13);
    consumptionTf.textColor = kPinkColor;
    consumptionTf.textAlignment = NSTextAlignmentCenter;
    consumptionTf.clearButtonMode = UITextFieldViewModeWhileEditing;
    [whiteView addSubview:consumptionTf];
    consumptionTf.userInteractionEnabled = NO;
    self.consumptionTf = consumptionTf;
    consumptionTf.keyboardType = UIKeyboardTypeNumberPad;
    consumptionTf.delegate = self;
    
    UITextField *consumptionIntegralTf = [[UITextField alloc] initWithFrame:SARectMake(190, 35, 80, 50)];
    consumptionIntegralTf.placeholder = @"";
    consumptionIntegralTf.font = kFont(13);
    consumptionIntegralTf.textColor = kPinkColor;
    consumptionIntegralTf.textAlignment = NSTextAlignmentCenter;
    consumptionIntegralTf.clearButtonMode = UITextFieldViewModeWhileEditing;
    [whiteView addSubview:consumptionIntegralTf];
    consumptionIntegralTf.userInteractionEnabled = NO;
    self.consumptionIntegralTf = consumptionIntegralTf;
    consumptionIntegralTf.keyboardType = UIKeyboardTypeNumberPad;
    consumptionIntegralTf.delegate = self;
    
    UILabel *topUpLab = [[UILabel alloc] initWithFrame:SARectMake(20, 85, 40, 50)];
    topUpLab.text = @"充值";
    topUpLab.textAlignment = NSTextAlignmentLeft;
    topUpLab.font = kFont(15);
    topUpLab.textColor = kBlackColor;
    [whiteView addSubview:topUpLab];
    
    UILabel *topUpLab2 = [[UILabel alloc] initWithFrame:SARectMake(140, 85, 50, 50)];
    topUpLab2.text = @"元赠送";
    topUpLab2.textAlignment = NSTextAlignmentLeft;
    topUpLab2.font = kFont(15);
    topUpLab2.textColor = kBlackColor;
    [whiteView addSubview:topUpLab2];
    
    UILabel *topUpLab3 = [[UILabel alloc] initWithFrame:SARectMake(270, 85, 50, 50)];
    topUpLab3.text = @"个积分";
    topUpLab3.textAlignment = NSTextAlignmentLeft;
    topUpLab3.font = kFont(15);
    topUpLab3.textColor = kBlackColor;
    [whiteView addSubview:topUpLab3];
    
    UIView *line4 = [[UIView alloc] initWithFrame:SARectMake(55, 124, 80, 1)];
    line4.backgroundColor = kBlackColor;
    [whiteView addSubview:line4];
    line4.hidden = YES;
    self.line4 = line4;
    
    UIView *line5 = [[UIView alloc] initWithFrame:SARectMake(190, 124, 80, 1)];
    line5.backgroundColor = kBlackColor;
    [whiteView addSubview:line5];
    line5.hidden = YES;
    self.line5 = line5;
    
    UITextField *topUpTf = [[UITextField alloc] initWithFrame:SARectMake(55, 85, 80, 50)];
    topUpTf.placeholder = @"";
    topUpTf.font = kFont(15);
    topUpTf.textColor = kPinkColor;
    topUpTf.textAlignment = NSTextAlignmentCenter;
    topUpTf.clearButtonMode = UITextFieldViewModeWhileEditing;
    topUpTf.userInteractionEnabled = NO;
    [whiteView addSubview:topUpTf];
    self.topUpTf = topUpTf;
    topUpTf.keyboardType = UIKeyboardTypeNumberPad;
    topUpTf.delegate = self;
    
    UITextField *topUpIntegralTf = [[UITextField alloc] initWithFrame:SARectMake(190, 85, 80, 50)];
    topUpIntegralTf.placeholder = @"";
    topUpIntegralTf.font = kFont(15);
    topUpIntegralTf.textColor = kPinkColor;
    topUpIntegralTf.textAlignment = NSTextAlignmentCenter;
    topUpIntegralTf.clearButtonMode = UITextFieldViewModeWhileEditing;
    [whiteView addSubview:topUpIntegralTf];
    topUpIntegralTf.userInteractionEnabled = NO;
    self.topUpIntegralTf = topUpIntegralTf;
    topUpIntegralTf.keyboardType = UIKeyboardTypeNumberPad;
    topUpIntegralTf.delegate = self;
    
    UIView *whiteView2 = [[UIView alloc] initWithFrame:SARectMake(0, StatusHeight + 141, kBaseScreenWidth, 135)];
    whiteView2.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:whiteView2];
    
    UILabel *deductionLab = [[UILabel alloc] initWithFrame:SARectMake(20, 0, 70, 35)];
    deductionLab.text = @"抵扣积分";
    deductionLab.textColor = kGrayColor;
    deductionLab.textAlignment = NSTextAlignmentLeft;
    deductionLab.font = kFont(15);
    [whiteView2 addSubview:deductionLab];
    
    UIButton *switchBtn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    switchBtn2.frame = SARectMake(90, 0, 60, 35);
    [switchBtn2 setImage:[UIImage imageNamed:@"gray_switch"] forState:UIControlStateNormal];
    [switchBtn2 setImage:[UIImage imageNamed:@"green_switch"] forState:UIControlStateSelected];
    [switchBtn2 addTarget:self action:@selector(clickedSwitchBtn:) forControlEvents:UIControlEventTouchUpInside];
    [whiteView2 addSubview:switchBtn2];
    self.switchBtn2 = switchBtn2;
    
    UIButton *editBtn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    editBtn2.frame = SARectMake(kBaseScreenWidth - 65, 0, 50, 35);
    [editBtn2 setImage:[UIImage imageNamed:@"bule_edit"] forState:UIControlStateNormal];
    [editBtn2 addTarget:self action:@selector(clickedEditBtn2) forControlEvents:UIControlEventTouchUpInside];
    [whiteView2 addSubview:editBtn2];
    self.editBtn2 = editBtn2;
    
    UIButton *saveBtn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    saveBtn2.frame = SARectMake(kBaseScreenWidth - 65, 0, 50, 35);
    [saveBtn2 setTitle:@"保存" forState:UIControlStateNormal];
    [saveBtn2 setTitleColor:kColor(70, 112, 251, 1) forState:UIControlStateNormal];
    [saveBtn2 addTarget:self action:@selector(clickedSaveBtn2) forControlEvents:UIControlEventTouchUpInside];
    saveBtn2.hidden = YES;
    saveBtn2.titleLabel.font = kFont(15);
    [whiteView2 addSubview:saveBtn2];
    self.saveBtn2 = saveBtn2;
    
    UIButton *cancleBtn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    cancleBtn2.frame = SARectMake(kBaseScreenWidth - 120, 0, 50, 35);
    [cancleBtn2 setTitle:@"取消" forState:UIControlStateNormal];
    [cancleBtn2 setTitleColor:kColor(70, 112, 251, 1) forState:UIControlStateNormal];
    [cancleBtn2 addTarget:self action:@selector(clickedCancleBtn2) forControlEvents:UIControlEventTouchUpInside];
    cancleBtn2.hidden = YES;
    cancleBtn2.titleLabel.font = kFont(15);
    [whiteView2 addSubview:cancleBtn2];
    self.cancleBtn2 = cancleBtn2;
    
    UIView *whiteView2line = [[UIView alloc] initWithFrame:SARectMake(0, 34, kBaseScreenWidth, 1)];
    whiteView2line.backgroundColor = kLineColor;
    [whiteView2 addSubview:whiteView2line];
    
    UILabel *useIntegralLab = [[UILabel alloc] initWithFrame:SARectMake(20, 35, 40, 50)];
    useIntegralLab.text = @"使用";
    useIntegralLab.textAlignment = NSTextAlignmentLeft;
    useIntegralLab.font = kFont(15);
    useIntegralLab.textColor = kBlackColor;
    [whiteView2 addSubview:useIntegralLab];
    
    UILabel *useIntegralLab2 = [[UILabel alloc] initWithFrame:SARectMake(140, 35, 200, 50)];
    useIntegralLab2.text = @"积分,可抵扣1.00元";
    useIntegralLab2.textAlignment = NSTextAlignmentLeft;
    useIntegralLab2.font = kFont(15);
    useIntegralLab2.textColor = kBlackColor;
    [whiteView2 addSubview:useIntegralLab2];
    
    UIView *line6 = [[UIView alloc] initWithFrame:SARectMake(55, 74, 80, 1)];
    line6.backgroundColor = kBlackColor;
    [whiteView2 addSubview:line6];
    line6.hidden = YES;
    self.line6 = line6;
    
    UITextField *useIntegralTf = [[UITextField alloc] initWithFrame:SARectMake(55, 35, 80, 50)];
    useIntegralTf.placeholder = @"";
    useIntegralTf.font = kFont(15);
    useIntegralTf.textColor = kPinkColor;
    useIntegralTf.textAlignment = NSTextAlignmentCenter;
    useIntegralTf.clearButtonMode = UITextFieldViewModeWhileEditing;
    [whiteView2 addSubview:useIntegralTf];
    self.useIntegralTf = useIntegralTf;
    useIntegralTf.userInteractionEnabled = NO;
    useIntegralTf.keyboardType = UIKeyboardTypeNumberPad;
    useIntegralTf.delegate = self;
    
    UILabel *deductionIntegralLab = [[UILabel alloc] initWithFrame:SARectMake(20, 85, 125, 50)];
    deductionIntegralLab.text = @"单笔订单抵扣上限";
    deductionIntegralLab.textAlignment = NSTextAlignmentLeft;
    deductionIntegralLab.font = kFont(15);
    deductionIntegralLab.textColor = kBlackColor;
    [whiteView2 addSubview:deductionIntegralLab];
    
    UILabel *deductionIntegralLab2 = [[UILabel alloc] initWithFrame:SARectMake(220, 85, 50, 50)];
    deductionIntegralLab2.text = @"元";
    deductionIntegralLab2.textAlignment = NSTextAlignmentLeft;
    deductionIntegralLab2.font = kFont(15);
    deductionIntegralLab2.textColor = kBlackColor;
    [whiteView2 addSubview:deductionIntegralLab2];
    
    UIView *line7 = [[UIView alloc] initWithFrame:SARectMake(140, 124, 80, 1)];
    line7.backgroundColor = kBlackColor;
    [whiteView2 addSubview:line7];
    line7.hidden = YES;
    self.line7 = line7;
    
    UITextField *deductionIntegralTf = [[UITextField alloc] initWithFrame:SARectMake(140, 85, 80, 50)];
    deductionIntegralTf.placeholder = @"";
    deductionIntegralTf.font = kFont(15);
    deductionIntegralTf.textColor = kPinkColor;
    deductionIntegralTf.textAlignment = NSTextAlignmentCenter;
    deductionIntegralTf.clearButtonMode = UITextFieldViewModeWhileEditing;
    [whiteView2 addSubview:deductionIntegralTf];
    self.deductionIntegralTf = deductionIntegralTf;
    deductionIntegralTf.userInteractionEnabled = NO;
    deductionIntegralTf.keyboardType = UIKeyboardTypeNumberPad;
    deductionIntegralTf.delegate = self;
    
    UIView *whiteView3 = [[UIView alloc] initWithFrame:SARectMake(0, StatusHeight + 282, kBaseScreenWidth, 135)];
    whiteView3.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:whiteView3];
    
    UILabel *resetLab = [[UILabel alloc] initWithFrame:SARectMake(20, 0, 70, 35)];
    resetLab.text = @"积分清零";
    resetLab.textColor = kGrayColor;
    resetLab.textAlignment = NSTextAlignmentLeft;
    resetLab.font = kFont(15);
    [whiteView3 addSubview:resetLab];
    
    UIButton *switchBtn3 = [UIButton buttonWithType:UIButtonTypeCustom];
    switchBtn3.frame = SARectMake(90, 0, 60, 35);
    [switchBtn3 setImage:[UIImage imageNamed:@"gray_switch"] forState:UIControlStateNormal];
    [switchBtn3 setImage:[UIImage imageNamed:@"green_switch"] forState:UIControlStateSelected];
    [switchBtn3 addTarget:self action:@selector(clickedSwitchBtn:) forControlEvents:UIControlEventTouchUpInside];
    [whiteView3 addSubview:switchBtn3];
    self.switchBtn3 = switchBtn3;
    
    UIButton *editBtn3 = [UIButton buttonWithType:UIButtonTypeCustom];
    editBtn3.frame = SARectMake(kBaseScreenWidth - 65, 0, 50, 35);
    [editBtn3 setImage:[UIImage imageNamed:@"bule_edit"] forState:UIControlStateNormal];
    [editBtn3 addTarget:self action:@selector(clickedEditBtn3) forControlEvents:UIControlEventTouchUpInside];
    [whiteView3 addSubview:editBtn3];
    self.editBtn3 = editBtn3;
    
    UIButton *saveBtn3 = [UIButton buttonWithType:UIButtonTypeCustom];
    saveBtn3.frame = SARectMake(kBaseScreenWidth - 65, 0, 50, 35);
    [saveBtn3 setTitle:@"保存" forState:UIControlStateNormal];
    [saveBtn3 setTitleColor:kColor(70, 112, 251, 1) forState:UIControlStateNormal];
    [saveBtn3 addTarget:self action:@selector(clickedSaveBtn3) forControlEvents:UIControlEventTouchUpInside];
    saveBtn3.hidden = YES;
    saveBtn3.titleLabel.font = kFont(15);
    [whiteView3 addSubview:saveBtn3];
    self.saveBtn3 = saveBtn3;
    
    UIButton *cancleBtn3 = [UIButton buttonWithType:UIButtonTypeCustom];
    cancleBtn3.frame = SARectMake(kBaseScreenWidth - 120, 0, 50, 35);
    [cancleBtn3 setTitle:@"取消" forState:UIControlStateNormal];
    [cancleBtn3 setTitleColor:kColor(70, 112, 251, 1) forState:UIControlStateNormal];
    [cancleBtn3 addTarget:self action:@selector(clickedCancleBtn3) forControlEvents:UIControlEventTouchUpInside];
    cancleBtn3.hidden = YES;
    cancleBtn3.titleLabel.font = kFont(15);
    [whiteView3 addSubview:cancleBtn3];
    self.cancleBtn3 = cancleBtn3;
    
    UIView *whiteView3line = [[UIView alloc] initWithFrame:SARectMake(0, 34, kBaseScreenWidth, 1)];
    whiteView3line.backgroundColor = kLineColor;
    [whiteView3 addSubview:whiteView3line];
    
    UILabel *resetDateLab = [[UILabel alloc] initWithFrame:SARectMake(20, 35, 70, 50)];
    resetDateLab.text = @"清零日期";
    resetDateLab.textAlignment = NSTextAlignmentLeft;
    resetDateLab.font = kFont(15);
    resetDateLab.textColor = kBlackColor;
    [whiteView3 addSubview:resetDateLab];
    
    UIButton *dateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    dateBtn.frame = SARectMake(93, 42, 140, 36);
    [dateBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
    dateBtn.titleLabel.font = kFont(15);
    [dateBtn addTarget:self action:@selector(clickedDateBtn) forControlEvents:UIControlEventTouchUpInside];
    [whiteView3 addSubview:dateBtn];
    dateBtn.userInteractionEnabled = NO;
    dateBtn.layer.cornerRadius = kScaleNum(5);
    dateBtn.layer.borderWidth = kScaleNum(1);
    dateBtn.layer.borderColor = kColor(230, 230, 230, 1).CGColor;
    dateBtn.layer.masksToBounds = YES;
    self.dateBtn = dateBtn;
    
    UILabel *tipLab = [[UILabel alloc] initWithFrame:SARectMake(20, 85, 340, 50)];
    tipLab.text = @"提示：到期所有会员的积分会在晚上1点清零";
    tipLab.textAlignment = NSTextAlignmentLeft;
    tipLab.font = kFont(15);
    tipLab.textColor = kLightgGrayColor;
    [whiteView3 addSubview:tipLab];
    
    [self.systemSettingsListAPI sendRequestToServerWithActivityViewAndMask:GET];
}


-(SASystemSettingsListAPI *)systemSettingsListAPI {
    if (!_systemSettingsListAPI) {
        _systemSettingsListAPI = [SASystemSettingsListAPI apiWithDelegate:self];
    }
    return _systemSettingsListAPI;
}


-(SASystemSettingsCheckAPI *)systemSettingsCheckAPI {
    if (!_systemSettingsCheckAPI) {
        _systemSettingsCheckAPI = [SASystemSettingsCheckAPI apiWithDelegate:self];
    }
    return _systemSettingsCheckAPI;
}

-(SASystemSettingsCheckAPI *)systemSettingsCheckAPI2 {
    if (!_systemSettingsCheckAPI2) {
        _systemSettingsCheckAPI2 = [SASystemSettingsCheckAPI apiWithDelegate:self];
    }
    return _systemSettingsCheckAPI2;
}

-(SASystemSettingsCheckAPI *)systemSettingsCheckAPI3 {
    if (!_systemSettingsCheckAPI3) {
        _systemSettingsCheckAPI3 = [SASystemSettingsCheckAPI apiWithDelegate:self];
    }
    return _systemSettingsCheckAPI3;
}

-(SASystemSettingsCheckAPI *)systemSettingsCheckAPI4 {
    if (!_systemSettingsCheckAPI4) {
        _systemSettingsCheckAPI4 = [SASystemSettingsCheckAPI apiWithDelegate:self];
    }
    return _systemSettingsCheckAPI4;
}

-(SASystemSettingsCheckAPI *)systemSettingsCheckAPI5 {
    if (!_systemSettingsCheckAPI5) {
        _systemSettingsCheckAPI5 = [SASystemSettingsCheckAPI apiWithDelegate:self];
    }
    return _systemSettingsCheckAPI5;
}

-(SASystemSettingsCheckAPI *)systemSettingsCheckAPI6 {
    if (!_systemSettingsCheckAPI6) {
        _systemSettingsCheckAPI6 = [SASystemSettingsCheckAPI apiWithDelegate:self];
    }
    return _systemSettingsCheckAPI6;
}

-(NSMutableArray<SACommoditySpecialFeesModel *> *)dataMarr {
    if (!_dataMarr) {
        _dataMarr = [NSMutableArray array];
    }
    return _dataMarr;
}

@end
